<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{.title}} - 用户登录</title>
    <link href="/static/css/app.css" rel="stylesheet">
</head>
<body class="bg-light">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6 col-lg-4">
                <div class="card shadow-sm mt-5">
                    <div class="card-header bg-primary text-white text-center">
                        <h4 class="mb-0">企业云资源申请系统</h4>
                        <small>基于 OpenStack Keystone 身份认证</small>
                    </div>
                    <div class="card-body">
                        {{if .error}}
                        <div class="alert alert-danger" role="alert">
                            {{.error}}
                        </div>
                        {{end}}
                        
                        <form method="POST" action="/login">
                            <div class="mb-3">
                                <label for="username" class="form-label">用户名</label>
                                <input type="text" class="form-control" id="username" name="username" required>
                            </div>
                            <div class="mb-3">
                                <label for="password" class="form-label">密码</label>
                                <input type="password" class="form-control" id="password" name="password" required>
                            </div>
                            <div class="mb-3">
                                <label for="domain" class="form-label">域</label>
                                <input type="text" class="form-control" id="domain" name="domain" value="company-cloud" readonly>
                            </div>
                            <div class="mb-3">
                                <small class="form-text text-muted">系统将自动选择您有权限的项目进行认证</small>
                            </div>
                            <button type="submit" class="btn btn-primary w-100">登录</button>
                        </form>
                    </div>
                </div>
                
                <!-- 测试账号信息 -->
                <div class="card mt-4">
                    <div class="card-header">
                        <h6 class="mb-0">测试账号信息</h6>
                    </div>
                    <div class="card-body">
                        <small class="text-muted">请确保已按照README完成Keystone配置</small>
                        {{range .users}}
                        <div class="border rounded p-2 mb-2 bg-light">
                            <strong>{{.type}}</strong><br>
                            <small>
                                用户名: <code>{{.username}}</code><br>
                                密码: <code>{{.password}}</code><br>
                                {{.description}}
                            </small>
                        </div>
                        {{end}}
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        // 快速填充测试账号
        document.querySelectorAll('.border.rounded').forEach(function(card) {
            card.style.cursor = 'pointer';
            card.addEventListener('click', function() {
                const username = this.querySelector('code').textContent;
                const password = this.querySelectorAll('code')[1].textContent;
                document.getElementById('username').value = username;
                document.getElementById('password').value = password;
            });
        });
    </script>
</body>
</html>